package com.wfm.tmp;

import org.junit.Test;

import java.util.BitSet;

public class BitSetTest {
    class MyBitSet{
        int[] bitSet;
        public MyBitSet(int N){
            bitSet = new int[N/32+1];
        }
        public void set(int num){
            int i = num/32;
            int j = num%32;
            bitSet[i]|=(1<<j);
        }
        public boolean get(int num){
            int i = num/32;
            int j = num%32;
            return (bitSet[i]&(1<<j))!=0;
        }
    }

    @Test
    public void test(){
        MyBitSet myBitSet = new MyBitSet(1000);
        int[] a={1,2,3,4,5,1,3,8,9};
        for (int i = 0; i < a.length; i++) {
            myBitSet.set(a[i]);
        }
        int cnt=0;
        for (int i = 0; i < myBitSet.bitSet.length; i++) {
            boolean b = myBitSet.get(i);
            if(b) cnt++;
        }
        System.out.println(cnt);
    }
}
